/**
 * @title RechargeEBankActivity.java
 * @package com.esun.cheetah.view.personal.recharg
 * @description 
 * @author liugan
 * @date 2012-4-25
 * @copyright 深圳市易讯天空
 */
package com.esun.cheetah.view.personal.recharg;

import com.esun.cheetah.R;
import com.esun.cheetah.biz.personal.personalinfo.UserInfo;
import com.esun.cheetah.view.custom.CustomChooseDialog;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;

/**
 * @title RechargeEBankActivity
 * @description 银行卡充值界面
 * @author liugan
 */
public class RechargeBankActivity extends Activity {

	private Button mBackButton;
	private WebView mWebView;
	private Handler mHandler = new Handler();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recharge_bank_activity);
		mBackButton = (Button) findViewById(R.id.btn_recharge_bank_tab_back);
		mBackButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		mWebView = (WebView) findViewById(R.id.recharge_bank_webview);

		WebSettings webSettings = mWebView.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webSettings.setSaveFormData(false);
		webSettings.setSavePassword(false);
		webSettings.setSupportZoom(false);
		mWebView.setWebChromeClient(new MyWebChromeClient());
		mWebView.addJavascriptInterface(new JSCallBack(), "client");

		mWebView.setBackgroundColor(0);
		final String ck = UserInfo.getUserInfo().getCk();
		final String userName = UserInfo.getUserInfo().getUserName();
		final String password = UserInfo.getUserInfo().getUserpwdMD5();
		String url = "http://ws.500wan.com/pages/interface/client/webview/user/bankCardCharge.php?ck="
				+ ck + "&username=" + userName + "&password=" + password;
		mWebView.loadUrl(url);
	}

	class JSCallBack {
		public void showRechargeSuccessDialog(final String title,
				final String message) {
			Log.e("JSCallBack", "JSCallBack被调用");
			mHandler.post(new ShowDialogRunnable(title, message));

		}
	}

	class ShowDialogRunnable implements Runnable {
		private String mMessage;
		private String mTitle;

		public ShowDialogRunnable(String title, String message) {
			this.mTitle = title;
			this.mMessage = message;
		}

		@Override
		public void run() {
			CustomChooseDialog dialog = new CustomChooseDialog(
					RechargeBankActivity.this);
			Log.e("RechargeBank", mMessage);
			dialog.setTitle(this.mTitle);
			dialog.setMessage(this.mMessage);
			dialog.setLeftButtonText("购彩");
			dialog.setOnLeftButtonClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					setResult(RechargeMenuPage.RESULT_CODE_TO_BUY_LOTTERY);
					mWebView.destroy();
					finish();
				}
			});

			dialog.setRightButtonText("查看账户");
			dialog.setOnRightButtonClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					setResult(RechargeMenuPage.RESULT_CODE_TO_CENTER);
					mWebView.destroy();
					finish();
				}
			});

			dialog.show();

		}

	}
}
